/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package tfmcbs.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import tfmcbs.Interface;
import tfmcbs.ProvidingPort;
import tfmcbs.Realization;
import tfmcbs.RequiringPort;
import tfmcbs.TfmcbsPackage;
import tfmcbs.Usage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Interface</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link tfmcbs.impl.InterfaceImpl#isIsAbstract <em>Is Abstract</em>}</li>
 *   <li>{@link tfmcbs.impl.InterfaceImpl#getUsages <em>Usages</em>}</li>
 *   <li>{@link tfmcbs.impl.InterfaceImpl#getRealizations <em>Realizations</em>}</li>
 *   <li>{@link tfmcbs.impl.InterfaceImpl#getRequiringPorts <em>Requiring Ports</em>}</li>
 *   <li>{@link tfmcbs.impl.InterfaceImpl#getProvidingPorts <em>Providing Ports</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class InterfaceImpl extends EntityImpl implements Interface {
	/**
	 * The default value of the '{@link #isIsAbstract() <em>Is Abstract</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isIsAbstract()
	 * @generated
	 * @ordered
	 */
	protected static final boolean IS_ABSTRACT_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isIsAbstract() <em>Is Abstract</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isIsAbstract()
	 * @generated
	 * @ordered
	 */
	protected boolean isAbstract = IS_ABSTRACT_EDEFAULT;

	/**
	 * The cached value of the '{@link #getUsages() <em>Usages</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUsages()
	 * @generated
	 * @ordered
	 */
	protected EList<Usage> usages;

	/**
	 * The cached value of the '{@link #getRealizations() <em>Realizations</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRealizations()
	 * @generated
	 * @ordered
	 */
	protected EList<Realization> realizations;

	/**
	 * The cached value of the '{@link #getRequiringPorts() <em>Requiring Ports</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRequiringPorts()
	 * @generated
	 * @ordered
	 */
	protected EList<RequiringPort> requiringPorts;

	/**
	 * The cached value of the '{@link #getProvidingPorts() <em>Providing Ports</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProvidingPorts()
	 * @generated
	 * @ordered
	 */
	protected EList<ProvidingPort> providingPorts;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected InterfaceImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return TfmcbsPackage.Literals.INTERFACE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isIsAbstract() {
		return isAbstract;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIsAbstract(boolean newIsAbstract) {
		boolean oldIsAbstract = isAbstract;
		isAbstract = newIsAbstract;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TfmcbsPackage.INTERFACE__IS_ABSTRACT, oldIsAbstract, isAbstract));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Usage> getUsages() {
		if (usages == null) {
			usages = new EObjectWithInverseResolvingEList<Usage>(Usage.class, this, TfmcbsPackage.INTERFACE__USAGES, TfmcbsPackage.USAGE__INTERFACE);
		}
		return usages;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Realization> getRealizations() {
		if (realizations == null) {
			realizations = new EObjectWithInverseResolvingEList<Realization>(Realization.class, this, TfmcbsPackage.INTERFACE__REALIZATIONS, TfmcbsPackage.REALIZATION__INTERFACE);
		}
		return realizations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<RequiringPort> getRequiringPorts() {
		if (requiringPorts == null) {
			requiringPorts = new EObjectWithInverseResolvingEList<RequiringPort>(RequiringPort.class, this, TfmcbsPackage.INTERFACE__REQUIRING_PORTS, TfmcbsPackage.REQUIRING_PORT__DELEGATE);
		}
		return requiringPorts;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ProvidingPort> getProvidingPorts() {
		if (providingPorts == null) {
			providingPorts = new EObjectWithInverseResolvingEList<ProvidingPort>(ProvidingPort.class, this, TfmcbsPackage.INTERFACE__PROVIDING_PORTS, TfmcbsPackage.PROVIDING_PORT__DELEGATE);
		}
		return providingPorts;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TfmcbsPackage.INTERFACE__USAGES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getUsages()).basicAdd(otherEnd, msgs);
			case TfmcbsPackage.INTERFACE__REALIZATIONS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getRealizations()).basicAdd(otherEnd, msgs);
			case TfmcbsPackage.INTERFACE__REQUIRING_PORTS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getRequiringPorts()).basicAdd(otherEnd, msgs);
			case TfmcbsPackage.INTERFACE__PROVIDING_PORTS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getProvidingPorts()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TfmcbsPackage.INTERFACE__USAGES:
				return ((InternalEList<?>)getUsages()).basicRemove(otherEnd, msgs);
			case TfmcbsPackage.INTERFACE__REALIZATIONS:
				return ((InternalEList<?>)getRealizations()).basicRemove(otherEnd, msgs);
			case TfmcbsPackage.INTERFACE__REQUIRING_PORTS:
				return ((InternalEList<?>)getRequiringPorts()).basicRemove(otherEnd, msgs);
			case TfmcbsPackage.INTERFACE__PROVIDING_PORTS:
				return ((InternalEList<?>)getProvidingPorts()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case TfmcbsPackage.INTERFACE__IS_ABSTRACT:
				return isIsAbstract();
			case TfmcbsPackage.INTERFACE__USAGES:
				return getUsages();
			case TfmcbsPackage.INTERFACE__REALIZATIONS:
				return getRealizations();
			case TfmcbsPackage.INTERFACE__REQUIRING_PORTS:
				return getRequiringPorts();
			case TfmcbsPackage.INTERFACE__PROVIDING_PORTS:
				return getProvidingPorts();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case TfmcbsPackage.INTERFACE__IS_ABSTRACT:
				setIsAbstract((Boolean)newValue);
				return;
			case TfmcbsPackage.INTERFACE__USAGES:
				getUsages().clear();
				getUsages().addAll((Collection<? extends Usage>)newValue);
				return;
			case TfmcbsPackage.INTERFACE__REALIZATIONS:
				getRealizations().clear();
				getRealizations().addAll((Collection<? extends Realization>)newValue);
				return;
			case TfmcbsPackage.INTERFACE__REQUIRING_PORTS:
				getRequiringPorts().clear();
				getRequiringPorts().addAll((Collection<? extends RequiringPort>)newValue);
				return;
			case TfmcbsPackage.INTERFACE__PROVIDING_PORTS:
				getProvidingPorts().clear();
				getProvidingPorts().addAll((Collection<? extends ProvidingPort>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case TfmcbsPackage.INTERFACE__IS_ABSTRACT:
				setIsAbstract(IS_ABSTRACT_EDEFAULT);
				return;
			case TfmcbsPackage.INTERFACE__USAGES:
				getUsages().clear();
				return;
			case TfmcbsPackage.INTERFACE__REALIZATIONS:
				getRealizations().clear();
				return;
			case TfmcbsPackage.INTERFACE__REQUIRING_PORTS:
				getRequiringPorts().clear();
				return;
			case TfmcbsPackage.INTERFACE__PROVIDING_PORTS:
				getProvidingPorts().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case TfmcbsPackage.INTERFACE__IS_ABSTRACT:
				return isAbstract != IS_ABSTRACT_EDEFAULT;
			case TfmcbsPackage.INTERFACE__USAGES:
				return usages != null && !usages.isEmpty();
			case TfmcbsPackage.INTERFACE__REALIZATIONS:
				return realizations != null && !realizations.isEmpty();
			case TfmcbsPackage.INTERFACE__REQUIRING_PORTS:
				return requiringPorts != null && !requiringPorts.isEmpty();
			case TfmcbsPackage.INTERFACE__PROVIDING_PORTS:
				return providingPorts != null && !providingPorts.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (isAbstract: ");
		result.append(isAbstract);
		result.append(')');
		return result.toString();
	}

} //InterfaceImpl
